package zhenwoproto

var OkStatus DatacheckReply = DatacheckReply{Code: 1000, Msg: "success", Error: ""}

func NewDataResponse() *DatacheckReply {
	return &DatacheckReply{}
}
func NewErrDataResponse(msg, err string) *DatacheckReply {
	return &DatacheckReply{Code: 1001, Msg: msg, Error: err}
}
func NewResponseErr(err error, ok_msg, err_msg string) *DatacheckReply {
	return NewDataResponse().OkErrResponse(err, ok_msg, err_msg)
}

func (n *DatacheckReply) OkErrResponse(err error, ok_msg, err_msg string) *DatacheckReply {
	if err == nil {
		return n.OkMsg(ok_msg)
	}
	return n.ErrMsg1001(err_msg, err.Error())
}

func (n *DatacheckReply) OkMsg(msg string) *DatacheckReply { return n.SetResponse(1000, msg, "") }
func (n *DatacheckReply) ErrMsg1001(msg, err string) *DatacheckReply {
	return n.SetResponse(1001, msg, err)
}
func (n *DatacheckReply) ErrMsg1111(msg, err string) *DatacheckReply {
	return n.SetResponse(1111, msg, err)
}
func (n *DatacheckReply) Success() *DatacheckReply { return n.SetResponse(1000, "success", "") }
func (n *DatacheckReply) IsSuccess() bool          { return n.Code == 1000 }
func (n *DatacheckReply) IsErr() bool              { return n.Code != 1000 }

func (n *DatacheckReply) SetResponse(code int32, msg, err string) *DatacheckReply {
	n.Code = code
	n.Msg = msg
	n.Error = err
	return n
}
